<template>
	<view class="content">
		<uni-card>
			<u-search placeholder="关键字查询" searchIconSize="44" shape="round" :inputStyle="{height:'30px'}"
				v-model="search" @custom="onSearch"></u-search>
			<u-gap height="25" bgColor="#fff"></u-gap>
			<uni-table ref="table" border stripe emptyText="暂无更多数据" @selection-change="selectionChange">
				<uni-tr>
					<uni-th align="center">地块编号</uni-th>
					<uni-th align="center">地块名称</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index" @click.native="goToTab(item.objectid)">
					<uni-td align="center">{{ item.bianhao }}</uni-td>
					<uni-td align="center">{{ item.name }}</uni-td>
				</uni-tr>
			</uni-table>
		</uni-card>

	</view>

</template>

<script>
	import {
		searchAndDraw
	} from '@/utils/initMap.js'
	export default {
		data() {
			return {
				search: '',
				tableData: [],
				letterArray: '',
				word: {},
				params: this.$store.state.user.params,
			}
		},
		mounted() {
			this.onSearch()
		},
		methods: {
			getTableData() {
				searchAndDraw(this.params).then(res => {
					this.tableData = res
				})
			},
			goToTab(objectid) {
				// uni.navigateTo({
				// 	url: "/pages/Land/details?objectid=" + objectid
				// })
				this.$emit('patternLocalization', objectid)
			},
			async onSearch() {
				// TODO 怎么清理store旧的条件
				let params = {
					sql: ''
				}
				if (this.params.sql) {
					params.sql = this.params.sql + ' and ( '

						+
						"  ( name like '%" + this.search + "%') " +
						" or ( bianhao like '%" + this.search + "%') " +
						" or ( quyu like '%" + this.search + "%') " +
						" or ( sizhi like '%" + this.search + "%') " +
						" or ( gdfs like '%" + this.search + "%') " +
						" or ( jdqk like '%" + this.search + "%') " +
						" or ( jcss like '%" + this.search + "%') " +
						" or ( bz like '%" + this.search + "%') " +
						" or ( ghyt like '%" + this.search + "%') " +
						" or ( bgdz like '%" + this.search + "%') " +
						" or ( qjdz like '%" + this.search + "%') " +
						" or ( rjl like '%" + this.search + "%') " +
						" or ( jzmd like '%" + this.search + "%') " +
						" or ( jzxg like '%" + this.search + "%') " +
						" or ( ldl like '%" + this.search + "%') "

						+
						' )'
				} else {
					params.sql = "(  ( name like '%" + this.search + "%') " +
						" or ( bianhao like '%" + this.search + "%') " +
						" or ( quyu like '%" + this.search + "%') " +
						" or ( sizhi like '%" + this.search + "%') " +
						" or ( gdfs like '%" + this.search + "%') " +
						" or ( jdqk like '%" + this.search + "%') " +
						" or ( jcss like '%" + this.search + "%') " +
						" or ( bz like '%" + this.search + "%') " +
						" or ( ghyt like '%" + this.search + "%') " +
						" or ( bgdz like '%" + this.search + "%') " +
						" or ( qjdz like '%" + this.search + "%') " +
						" or ( rjl like '%" + this.search + "%') " +
						" or ( jzmd like '%" + this.search + "%') " +
						" or ( jzxg like '%" + this.search + "%') " +
						" or ( ldl like '%" + this.search + "%') ) "

				}
				params.isZnxdSearch = true
				let res = await searchAndDraw(params);
				this.tableData = res;
			}

		},
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-bottom: 60px;
	}
</style>